package mf.com.controller.product;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import mf.com.Service.Product.SpecService;
import mf.com.entity.product.ProductSpec;
import mf.com.vo.common.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lmf
 * @Create: 2024/4/9 22:01
 * Description:  商品规格
 */
@RestController
@Tag(name = "商品规格")
@RequestMapping("/admin/product/productSpec/")
public class SpecController {
    @Resource
    private SpecService specService;

    @PostMapping("findAll")
    @Operation(summary = "查询所有规格")
    public Result<List<ProductSpec>> findAll(){
        return Result.success(specService.findAll());
    }

    @PostMapping("save")
    @Operation(summary = "新增规格")
    public Result<Integer> save(@RequestBody ProductSpec productSpec){
        return Result.success(specService.save(productSpec));
    }

    @PostMapping("update")
    @Operation(summary = "修改规格")
    public Result<Integer> update(@RequestBody ProductSpec productSpec){
        return Result.success(specService.update(productSpec));
    }

    @PostMapping("deleteById")
    @Operation(summary = "删除规格")
    public Result<Integer> deleteById(Integer id){
        return Result.success( specService.deleteById(id));
    }

    @PostMapping("findById")
    @Operation(summary = "查询规格")
    public Result<ProductSpec> findById(Integer id){
        return Result.success( specService.findById(id));
    }

    @PostMapping("findByPage/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询规格")
    public Result<PageInfo<ProductSpec>> findByPage(
            @RequestBody ProductSpec productSpec
            ,@PathVariable("pageNum") Integer pageNum
            ,@PathVariable("pageSize") Integer pageSize
    ){
        return Result.success(specService.findByPage(productSpec,pageNum,pageSize));
    }



}
